package deleteNode;

public class Solution {
      public class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }
    public ListNode deleteNode(ListNode head, int val) {
          if ( head == null ) return null;
          ListNode cur = head.next;
          ListNode parent = head;
          while ( cur!=null ) {
            if( cur.val == val ) {
                parent.next = cur.next;
            } else {
                parent = cur;
            }
            cur = cur.next;
        }
         return head.val == val? head.next : head;
    }
}
